package com.jiangjiang.eshop.membership.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.membership.convert.MemberPointDetailConvert;
import com.jiangjiang.eshop.membership.dao.MemberPointDetailMapper;
import com.jiangjiang.eshop.membership.domain.MemberPointDetailEntity;
import com.jiangjiang.eshop.membership.dto.MemberPointDetailDTO;
import com.jiangjiang.eshop.membership.dto.MemberPointDetailPageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName MemberPointDetailService
 * @Description TODO
 * @Author jhw
 * @Date 2021/8/22 16:44
 * @Version 1.0
 **/
@Service
public class MemberPointDetailService extends ServiceImpl<MemberPointDetailMapper, MemberPointDetailEntity> {
    @Autowired
    private MemberPointDetailConvert memberPointDetailConvert;

    /**
     * 用户积分变更明细分页查询
     *
     * @param dto 查询条件
     * @return 查询结果
     */
    public Page<MemberPointDetailDTO> queryForPage(MemberPointDetailPageDTO dto) {
        Page<MemberPointDetailEntity> page = new Page<>(dto.getPageNo(), dto.getPageSize(), true);
        LambdaQueryWrapper<MemberPointDetailEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(MemberPointDetailEntity::getUserAccountId, dto.getUserAccountId())
                .orderByDesc(MemberPointDetailEntity::getGmtCreate);

        return memberPointDetailConvert.convertEntityPage2DTOPage(this.getBaseMapper().selectPage(page, wrapper));
    }

}
